function number_format(number, decimals, dec_point, thousands_sep) {
	number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
	var n = !isFinite(+number) ? 0 : +number,
	prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
	sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
	dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
	s = '',
	toFixedFix = function (n, prec) {
		var k = Math.pow(10, prec);
		return '' + Math.round(n * k) / k;
	};
	// Fix for IE parseFloat(0.55).toFixed(0) = 0;
	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
	if (s[0].length > 3) {
		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
	}
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	}
	return s.join(dec);
}

var loaded = false;

var projectURL = $('#name a').attr('href');
$(document).ready(function(){
	project = projectURL.substring(projectURL.lastIndexOf('/') + 1);

	var funding = $($('#moneyraised h5')[1]).text().replace(/,/g,'').match(/(\d+)/g);
	var percent = parseInt((funding[0] / funding[1]) * 100);

	$($('#moneyraised h5')[1]).children('.num').after(number_format(percent) +'%');

	chrome.extension.sendRequest({'action': 'getOption', 'option': project},function(status){
		if(status !== 'FUNDED')
		{
			$('img.youre-a-backer').replaceWith('<div class="youre-a-backer '+ status +'"></div>');
		}
	});

	$('#content').css('position', 'relative');
	$('#content').prepend('<div class="trend_images" style="z-index:1;"></div>');
	$('#content .trend_images').append('<img style="display:inline;" id="dailychart" src="" width="940" height="270" />');
	$('#content .trend_images').append('<img style="display:inline;" id="dailypledges" src="" width="940" height="270" />');
	$('#content .trend_images').append('<img style="display:inline;" id="dailybackers" src="" width="940" height="270" />');
	$('#following-widget').before('<li class="trendy"><a class="trends" href="javascript:void(0);"></a></li>');
	$('a.trends').click(function(){
		if (loaded == false)
		{
			$('#content .trend_images #dailychart').attr('src', 'http://www.kicktraq.com'+ projectURL +'/dailychart.png');
			$('#content .trend_images #dailypledges').attr('src', 'http://www.kicktraq.com'+ projectURL +'/dailypledges.png');
			$('#content .trend_images #dailybackers').attr('src', 'http://www.kicktraq.com'+ projectURL +'/dailybackers.png');
			loaded = true;
		}
		$(this).toggleClass('active');
		$('.trend_images').slideToggle('slow', function(){});
	});
});